package org.spp.voronoi;

import org.spp.utilities.Point;

import java.util.List;

/**
 * Edge2D.java
 * @author Ilio Catallo, Eleonora Ciceri
 * @version 1.0
 * @see Edge
 * 
 * Description: class that specializes the edge of the Voronoi Diagram in case
 *              of bidimensinal points
 * 
 * Date: Jul 10, 2011
 */
public class Edge2D extends Edge{
  
    /**
     * Costructor for the class Edge2D
     * @param startVertex
     * @param endVertex 
     */
    public Edge2D(Vertex2D startVertex, Vertex2D endVertex, List<Facet> facets){
        super(startVertex, endVertex, facets);
        this.direction = new double[2];
    }
    
    /**
     * Constructor for the class Edge2D
     * @param startVertex
     * @param endVertex
     * @param centroid
     * @param facets 
     */
    public Edge2D(Vertex2D startVertex, Vertex2D endVertex, Centroid centroid, List<Facet> facets){
        super(startVertex, endVertex, centroid, facets);
    }
    
    /**
     * Method that computes the direction vector of the edge
     * @return direction 
     */
    @Override
    protected double[] computeDirection(){
        // Variables
        double[] coefficients = facets.get(0).getCoefficients();
        double[] newDirection = new double[]{-1*coefficients[1], coefficients[0]};
        
        // Normalize and correct the direction
        newDirection = Point.normalize(newDirection);        
        newDirection = correctDirection(newDirection);
        
        return newDirection;   
    }
    
    /**
     * Given the list of factes that create the edge, the method finds which cells
     * have in common the edge (to be implemented by Edge2D and Edge3D)
     * @return adjCells 
     */
    @Override
    protected List<Cell> findAdjCells(){
        return facets.get(0).getCells();
    }
    
}
